<template>
  <el-dialog
    width="40vw"
    append-to-body 
    top="20vh"
    :title="type == 0 ? '导出入库单':'导出采购计划'"
    :close-on-click-modal="false"
    :visible.sync="show"
  >
    <el-form :model="downForm" ref="downLoadFrom"  label-width="100px">
      <div style="display:flex;flex-direction:row;widt:100%">
        <!-- <template v-if="type == 1">
          <el-form-item label="订单状态" prop="status">
            <el-select
              v-model='downForm.status'
              clearable
              size='small'
              placeholder='订单状态'
              class='filter-item'
              style='width: 100px'
            >
              <el-option
                v-for='item in statusList'
                :key='item.id'
                :label='item.text'
                :value='item.id'
              />
            </el-select>
          </el-form-item>
        </template> -->
        <el-form-item v-if="type == 0" label="入库方式" prop="wareHousingType">
          <el-select
            v-model='downForm.wareHousingType'
            clearable
            size='small'
            placeholder='入库方式'
            class='filter-item'
            style='width: 100px'
          >
            <el-option
              v-for='item in wareHousingTypes'
              :key='item.id'
              :label='item.text'
              :value='item.id'
            />
          </el-select>
        </el-form-item>
      </div>
      <el-form-item label="入库时间" prop="startTime">
        <el-date-picker
          v-model="downForm.startTime"
          type="date"
          size="small"
          class="date-item"
          value-format="yyyy-MM-dd 00:00:00"
          placeholder="开始时间"
        />
      </el-form-item>
      <el-form-item label="入库时间" prop="endTime">
        <el-date-picker
          v-model="downForm.endTime"
          type="date"
          size="small"
          class="date-item"
          value-format="yyyy-MM-dd 23:59:59"
          placeholder="结束日期"
        />
      </el-form-item>
    </el-form>
    <div style="text-align:center">
    <el-button type="primary" size="medium" @click="onClickDownLoad">下载</el-button>
    <el-button size="medium" @click="show = false">关闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { outList } from '@/api/storageRoom/drugWareHousing';
import { mapGetters } from 'vuex';

export default {
  name: "exportWareHousing",
  computed: {
    ...mapGetters(["wareHousingTypes"]),
    statusList() {
      if(this.type == 1) {
        return [
          {id: 1, text: '待提交'},
          {id: 2, text: '待审核'},
          {id: 6, text: '待确定'},
          {id: 4, text: '已驳回'},
          {id: 5, text: '已取消'},
        ];
      }
      return [
        {id: 7, text: '待入库'},
        {id: 3, text: '已入库'},
      ];
    }
  },
  props: {
    // 0-入库, 1-采购计划
    type: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      downForm:{
        startTime: null,
        endTime: null,
        status: null,
        wareHousingType: null,
        type: 2
      },
      show: false,
    }
  },
  methods: {
    onClickDownLoad() {
      if(this.type == 1) {
        this.downForm.wareHousingType = 1;
        this.downForm.type = 1;
      } else {
        this.downForm.type = 2;
      }
      outList(this.downForm);
      setTimeout(() => {
        this.show = false;
        this.downForm = {
          dStartTime:'',
          dEndTime:'',
          dStatus:'',
          dWareHousingType:'',
        }
      }, 500);
    }
  }
}
</script>